package com.health;

import java.util.List;

import com.health.focusgroup.ChildActivity;
import com.health.focusgroup.GXYActivity;
import com.health.focusgroup.JSJBctivity;
import com.health.focusgroup.MaternityActivity;
import com.health.focusgroup.OlderActivity;
import com.health.focusgroup.TNBActivity;
import com.health.myd.GlobcontsFWMYD;
import com.health.tablebean.JTYSDoctorEvaluateBean;
import com.health.activity.tijian.YBQK_ZiLiWenJuanActivity;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

/**
 * 服务满意度评价
 * 
 * @author nova
 *
 */
public class FWMYDPJActivity extends NovaActivity implements OnClickListener {
	private static final String TAG = "FWMYDPJActivity";
	private static final String PJ_FCMY = "1";// 满意度状态（0:满意,1:非常满意,2:不满意）
	private static final String PJ_MY = "0";
	private static final String PJ_BMY = "2";
	private static final String PJ_YB = "4";
	private static final String PJ_FCBMY = "5";

	private static final String PJ_FMZ = "0";
	private static final String PJ_MZ = "1";

	private TextView title;
	private Button btn_back;
	public static Button btn_up;
	private RadioGroup rg_myd;
	private RadioButton rb_fcmy;
	private RadioButton rb_my;
	private RadioButton rb_bmy;
	private RadioButton rb_yb;
	private RadioButton rb_fcbmy;
	// private RadioGroup rg_sfmz;
	// private RadioButton rb_true;
	// private RadioButton rb_false;
	private String type;
	private String szfs;// 是否门诊

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		// WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.fwmyd_main);
		if (getIntent().hasExtra("type")) {
			type = getIntent().getStringExtra("type");
			szfs = getIntent().getStringExtra("szfs");
		}
		// Log.e("szfs", szfs+"+++++++++++++++++++++++");

		DisplayMetrics metric = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(metric);
		if (getWindowManager().getDefaultDisplay().getWidth() == 2048
				|| getWindowManager().getDefaultDisplay().getWidth() == 1920) {
			int width = (int) (metric.widthPixels * 0.7);
			int height = (int) (metric.heightPixels * 0.45);
			getWindow().setLayout(width, height);
		} else {
			int width = (int) (metric.widthPixels * 0.6);
			int height = (int) (metric.heightPixels * 0.45);
			getWindow().setLayout(width, height);
		}

		findViews();
		setListeners();
		// setData();
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.btn_back) {
			this.finish();
		} else if (v.getId() == R.id.btn_up) {
			saveData();
		}

	}

	@Override
	public void findViews() {
		title = (TextView) findViewById(R.id.title);

		btn_back = (Button) findViewById(R.id.btn_back);
		btn_up = (Button) findViewById(R.id.btn_up);

		rg_myd = (RadioGroup) findViewById(R.id.rg_myd);
		rb_fcmy = (RadioButton) findViewById(R.id.rb_fcmy);
		rb_my = (RadioButton) findViewById(R.id.rb_my);
		rb_bmy = (RadioButton) findViewById(R.id.rb_bmy);
		rb_yb = (RadioButton) findViewById(R.id.rb_yb);
		rb_fcbmy = (RadioButton) findViewById(R.id.rb_fcbmy);

		// rg_sfmz = (RadioGroup) findViewById(R.id.rg_sfmz);
		// rb_true = (RadioButton) findViewById(R.id.rb_true);
		// rb_false = (RadioButton) findViewById(R.id.rb_false);
		title.setText("服务满意度评价");
	}

	@Override
	public void setListeners() {
		btn_back.setOnClickListener(this);
		btn_up.setOnClickListener(this);

	}

	/**
	 * 保存数据 //满意度状态（0:满意,1:非常满意,2:不满意）
	 * 
	 * @author 王婷婷
	 * @date 2017年6月3日 下午4:27:34
	 */
	private void saveData() {
		String str_content = "";
		String Str_isOutpatients = "";
		// if (rb_true.isChecked()) {
		// Str_isOutpatients = PJ_MZ;
		// } else if (rb_false.isChecked()) {
		// Str_isOutpatients = PJ_FMZ;
		// } else {
		// showTextDialog("请选择是否门诊");
		// return;
		// }
		Str_isOutpatients = setSFMZ(type);

		if (rb_fcmy.isChecked()) {
			str_content = PJ_FCMY;
		} else if (rb_my.isChecked()) {
			str_content = PJ_MY;
		} else if (rb_bmy.isChecked()) {
			str_content = PJ_BMY;
		} else if (rb_yb.isChecked()) {
			str_content = PJ_YB;
		} else if (rb_fcbmy.isChecked()) {
			str_content = PJ_FCBMY;
		} else {
			showTextDialog("请选择满意度评价");
			return;
		}

		GlobcontsFWMYD.saveFWMYD(FWMYDPJActivity.this, NovaApplication.getUserInfo().getIDCARD(), type, str_content,
				Str_isOutpatients);
		showTextDialog("保存成功", FWMYDPJActivity.this);

		finish();

		if (ChildActivity.mChildActivity != null) {
			ChildActivity.mChildActivity.finish();
		}

		if (MaternityActivity.mMaternityActivity != null) {
			MaternityActivity.mMaternityActivity.finish();
		}

		if (GXYActivity.mGXYActivity != null) {
			GXYActivity.mGXYActivity.finish();
		}

		if (TNBActivity.mTNBActivity != null) {
			TNBActivity.mTNBActivity.finish();
		}

		if (OlderActivity.mOlderActivity != null) {
			OlderActivity.mOlderActivity.finish();
		}

		if (JSJBctivity.mJSJBctivity != null) {
			JSJBctivity.mJSJBctivity.finish();
		}

		if (YBQK_ZiLiWenJuanActivity.mYBQK_ZiLiWenJuanActivity != null) {
			YBQK_ZiLiWenJuanActivity.mYBQK_ZiLiWenJuanActivity.finish();
		}

	}

	private String setSFMZ(String type) {
		String sfmz = null;
		// 服务项目(02：儿童、03：孕产妇(产前)、04：孕产妇(产后)、05：老年人、06：高血压、07：糖尿病、08：重症精神病)
		// if (type.equals("02") || type.equals("05") || type.equals("03") ||
		// type.equals("04")|| type.equals("08")) {
		sfmz = PJ_FMZ;
		// }
		// DM04-04_1
		if (szfs.equals("DM04-04_1")) {
			sfmz = PJ_MZ;
		}
		// else{
		// sfmz = PJ_FMZ;
		// Log.e("tag", "----------------------------非门诊");
		// }

		return sfmz;
	}

	/**
	 * 设置数据
	 * 
	 * @author 王婷婷
	 * @date 2017年6月3日 下午5:14:59
	 */
	private void setData() {
		List<JTYSDoctorEvaluateBean> conts = NovaApplication.fdbmanger.findAllByWhere(JTYSDoctorEvaluateBean.class,
				"cardNum='" + NovaApplication.getUserInfo().getIDCARD() + "'");
		if (conts.size() > 0) {
			String str_myd = conts.get(0).getSatisfiedState();
			String str_sfmz = conts.get(0).getIsOutpatients();
			if (str_myd.equals(PJ_FCMY)) {
				rb_fcmy.setChecked(true);
			} else if (str_myd.equals(PJ_MY)) {
				rb_my.setChecked(true);
			} else if (str_myd.equals(PJ_BMY)) {
				rb_bmy.setChecked(true);
			} else if (str_myd.equals(PJ_YB)) {
				rb_yb.setChecked(true);
			} else if (str_myd.equals(PJ_FCBMY)) {
				rb_fcbmy.setChecked(true);
			}
			// else if (str_sfmz.equals(PJ_MZ)) {
			// rb_true.setChecked(true);
			// } else if (str_sfmz.equals(PJ_FMZ)) {
			// rb_false.setChecked(true);
			// }

			btn_up.setVisibility(View.GONE);
			jinyong(rb_fcmy, rb_my, rb_bmy, rb_yb, rb_fcbmy);
		}
	}

	/**
	 * 设置禁用
	 * 
	 * @param ets
	 * @author 王婷婷
	 * @date 2017年6月5日 上午11:42:49
	 */
	private void jinyong(View... ets) {
		for (View et : ets) {
			if (et != null) {
				if (et instanceof RadioButton) {
					et.setEnabled(false);
					et.setFocusable(false);
					// ((RadioGroup) et).getChildAt(i).setEnabled(false);
					et.setClickable(false);
				}
			}
		}
	}
}
